package cn.iocoder.yudao.module.system.controller.app.customerservice;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.system.controller.admin.customerservice.vo.CustomerServicePageReqVO;
import cn.iocoder.yudao.module.system.controller.app.customerservice.vo.AppCustomerServicePageReqVO;
import cn.iocoder.yudao.module.system.controller.app.customerservice.vo.AppCustomerServiceRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.customerservice.CustomerServiceDO;
import cn.iocoder.yudao.module.system.service.customerservice.CustomerServiceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "App - 客户服务")
@RestController
@RequestMapping("/system/customer-service")
@Validated
public class AppCustomerServiceController {

    @Resource
    private CustomerServiceService customerServiceService;

    @GetMapping("/get")
    @Operation(summary = "获得客户服务")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthenticated
    public CommonResult<AppCustomerServiceRespVO> getCustomerService(@RequestParam("id") Integer id) {
        CustomerServiceDO customerService = customerServiceService.getCustomerService(id);
        return success(BeanUtils.toBean(customerService, AppCustomerServiceRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得客户服务分页")
    @PreAuthenticated
    public CommonResult<PageResult<AppCustomerServiceRespVO>> getCustomerServicePage(@Valid AppCustomerServicePageReqVO pageReqVO) {
        PageResult<CustomerServiceDO> pageResult = customerServiceService.getCustomerServicePage(BeanUtils.toBean(pageReqVO, CustomerServicePageReqVO.class));
        return success(BeanUtils.toBean(pageResult, AppCustomerServiceRespVO.class));
    }

}